package com.gy.smart.handle.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gy.smart.R;
import com.gy.smart.handle.bean.HandleThemeBean;
import com.gy.smart.util.ListViewItemListener;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * 作者：gy on 17/1/5
 * 说明：
 */
public class HandleSelectAdapter extends BaseAdapter {

    private Context context;
    private ListViewItemListener listener;
    private List<HandleThemeBean> list;
    private int[] selects = new int[0];

    public HandleSelectAdapter(Context context,List<HandleThemeBean> list,int[] selects){
        this.context = context;
        this.list = list;
        this.selects = selects;
    }

    public void setListener(ListViewItemListener listener){
        this.listener = listener;
    }

    public void setSelect(int pos,int data){
        selects[pos] = data;
        this.notifyDataSetChanged();
    }

    public void setSelects(int[] selects){
        this.selects = selects;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.adapter_handle_select,null);
            holder.img = (ImageView) convertView.findViewById(R.id.adapter_handle_select_img);
            holder.imgSelect = (ImageView) convertView.findViewById(R.id.adapter_handle_select_img_select);
            holder.tvName = (TextView) convertView.findViewById(R.id.adapter_handle_select_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        if(selects[position] == 0){
            holder.imgSelect.setImageResource(R.mipmap.ic_handle_normal);
        } else {
            holder.imgSelect.setImageResource(R.mipmap.ic_handle_select);
        }
        ImageLoader.getInstance().displayImage(list.get(position).theme_img_url,holder.img);
        holder.tvName.setText(list.get(position).theme_name+"");
        return convertView;
    }

    class ViewHolder{
        ImageView img,imgSelect;
        TextView tvName;
    }
}
